Repository navigation
fix(types): accept an explicit undefined wherever a consumer writes an optional member - #418
Draft
YevheniiKotyrlo wants to merge 6 commits into
Draft
YevheniiKotyrlo wants to merge 6 commits into
YevheniiKotyrlo wants to merge 6 commits into
Conversation
Contributor
Author
YevheniiKotyrlo
force-pushed
the
rncss/types-optional-undefined
branch
from
October 11, 2026 12:35
6c6da94 to
d10ad90
Compare
YevheniiKotyrlo
marked this pull request as draft
October 20, 2026 09:53
…s package declares
React Native declares its optional props as `?: T | undefined`, and the props
this package adds were bare `?: string`. Under exactOptionalPropertyTypes the
two differ, so `className={condition ? "p-4" : undefined}` failed to compile,
and declaration merging cannot widen an existing prop from the consumer side.
Every optional member of types.d.ts and runtime.types.ts now takes
`| undefined`, except InlineStyleRecord's `s?: never`, which marks a key that
must stay absent. The props a mapping adds come from one StyledSourceProps
type, which the unmapped overload uses with DefaultStyledConfiguration, the
default mapping both platforms pass.
A test walks both files with the type checker under the flag and fails on any
optional member that rejects undefined, so a member added later is covered too.
…an entry left undefined
StyledConfigurationObject called ResolveDotPath<T, ComponentProps<C>>, the
reverse of its declaration ResolveDotPath<T, Path>, so a string target's
mapping type was never and only the target:false branch's Record checked a
mapping. With the arguments in order, an entry may be left undefined, and
mappingToConfig drops it, where nativeStyleMapping called `path.split(".")` on
it and threw.
YevheniiKotyrlo
force-pushed
the
rncss/types-optional-undefined
branch
from
October 20, 2026 15:02
8c8919f to
49ff1c9
Compare
…in a mapping A nativeStyleMapping key names a key of the compiled style, which a -rn- declaration can add under any name, so its keys stay open while React Native's style keys complete; the type no longer resolves the target, which halves its instantiations. The class props styled() adds stay writable, and the compiler, Metro, jest, Babel and useNativeCss options accept an explicit undefined.
…n a listed type that is gone
…nd drop fill and stroke keys
…out of jest's options
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Problem
React Native declares its own optional props as
?: T | undefined, while the props this package adds are bare?: string. UnderexactOptionalPropertyTypesthe two differ, and the difference falls on the most ordinary thing a consumer writes:styled()has the same bare members: theclassNameits unmapped overload adds,passThrough, and a mapping'snativeStyleMapping; so do the options a consumer writes for the compiler, Metro, the jest helper anduseNativeCss. A consumer's own declaration that widens such a prop takes effect only when it comes before this package's in the program.A mapping entry left
undefinedis also a runtime error:mappingToConfigkeeps it, andnativeStyleMappingcallspath.split(".")on it:Solution
types.d.tsandruntime.types.ts, and of the compiler's, Metro's, the jest helper's anduseNativeCss's options, takes| undefined, as React Native writes its own, exceptInlineStyleRecord'ss?: never, which marks a key that must stay absent. The jest helper's options leave outlogger, which the helper always sets itself.styled()mapping adds come from oneStyledSourcePropstype, whichStyledProps,StyledReactElementandStyledComponentuse, and which the unmapped overload uses withDefaultStyledConfiguration, the default mappingsrc/native/api.tsxandsrc/web/api.tsxboth pass. They stay writable, as the component's own props are.-rn-declaration, so any string is a key. The type no longer resolves the mapping's target, and an entry may be leftundefined, whichmappingToConfigdrops.Tests
src/__tests__/types/optional-members.test.tschecks both declaration files and the option types with the type checker, the flag on, and fails on any optional member that rejectsundefined. A type that resolves is read member by member, inherited, picked and mapped members included, down to the option types its members reach; a generic one is read as written, a mapped type overkeyof Tand a library type such asPartialover a type parameter among its forms. A listed type the file no longer declares fails the test. Its fixture holds each form, beside the ones that pass. Againstmainit reports 49 members, an inherited one under each type that inherits it; here none.src/__tests__/native/_styled-types.tsx: a mapping takes any style key, a-rn-declaration's among them, and an entry leftundefined, rejects a value naming no prop, and the class props stay writable; onmaintscfails theundefinedentry and the writable mapped prop.src/__tests__/types/styled.test.ts: the editor completes React Native's style keys whatever the target; it fails onmain.src/__tests__/native/styled.test.ios.tsx: a mapping entry set toundefinedmaps nothing. Onmainthe case failstsc, and its render throws.Verification
Every
ci.ymljob passes on this head merged intomainwith #477's harness fix: lint, typecheck, the tests (1350 passed), both builds, the web export, nothing unstaged, commitlint, and the iOS dev build on macOS 27.0.1 with Xcode 27.0, where CI pins 26.6.A
styled()mapping now costs the type checker about 8,100 instantiations against 35,200 onmain, andtsc --noEmitover this repository makes 930,621 type instantiations against 979,442. The runs, and the snippet above onmainand on this branch, are in this comment.Known limits
-rn-declaration can add any key to the style.styled()over Reanimated's animated components still exceeds the type checker's depth (TS2589, TS2590), as onmain, at about 15% fewer instantiations.CompilerOptions.loggerandConfig.nativeStyleMappingclears the 6 othersmainhas.Merge order
dir?: "ltr" | "rtl"toViewPropsandTextProps, and feat(metro): surface compiler warnings during a build #430 and fix(compiler): recover from a rule lightningcss cannot parse #493 addwarnings?: WarningLevelto Metro's options. Whichever lands second widens them, andoptional-members.test.tsfails until it does.nativeStyleMappingdeclaration insrc/runtime.types.ts.